<?php

//群主的活动中心
namespace Admin\Controller;

class HostactivityController extends AdminController {

	//展会列表
	public function index(){
        
		$zhanhui = M(tb_exhinf);
		$map['qID'] = UID;
		$sql = 'SELECT * FROM duijie_tb_exhinf;';
		$list = $zhanhui -> where($map) -> query($sql);
		$this -> assign('_list',$list);
		
		$this->meta_title = '展会列表';
		$this->display();
	}

	//添加展会
	public function add(){
			
		if(IS_POST){
			$exh = M('tb_exhinf');
			$data = $exh -> create();
			$data['qID'] = UID;
			if($data['zname'] == null){
				$this->error('展会名称不能为空！');
			}
			if($data['type'] == null){
				$this->error('展会类型不能为空！');
			}
			if(!$exh->add($data)){
				$this->error('展会添加失败！');
			} else {
				$this->success('展会添加成功！',U('index'));
			}
		}
		//应用领域数据
		$result = M('tb_teclab')->where(array('upid'=> 0))->field('id,name')->select();
		$this->assign('cate',$result);
      
		$this->meta_title = '新增展会';
		$this->display('edit');

	}
   
	//编辑展会
	public function edit($id){

		if(IS_POST){
			$exh = M('tb_exhinf');
			$exh -> create();
			$rst = $exh ->save();
			if($rst){
				$this->success('展会修改成功！',U('index'));
			}else{
				$this->error('修改失败！');
			}
		}else{
			$exh = M('tb_exhinf');

		    $data=$exh->find($id);
			$this->assign('data', $data);
			
			//应用数据记录
			$result = M('tb_teclab')->where(array('upid'=> 0))->field('id,name')->select();
			$this->assign('cate',$result);
			//dump($result);
			
			$this->display();
		}
	}

		// 	public function del($id=''){
		
		// 		$dem = M(tb_demand);
		// 		$dem->delete($id);
		// 		$this->success('删除成功！',U('index'));
					
		// 	}
	
	//开始展会
	public function start($id=''){
 		$exh = M(tb_exhinf);
 		$data['zstatus'] = '1';
 		$exh->where("id=$id")->save($data);	
 		$this->success('展会已开始',U('index'));
	}
	
	//结束展会
	public function end($id=''){
		$exh = M(tb_exhinf);
		$data['zstatus'] = '2';
		$exh->where("id=$id")->save($data);
		$this->success('展会已结束',U('index'));
	}
	
	//参展项目
	public function zxm($id=''){
		
		$tecach = M(tb_tecach);
		
		$map[zID] = $id;	
		
 		$list = $tecach -> join('duijie_tb_exhlab on duijie_tb_tecach.id=duijie_tb_exhlab.jID')	
 		
 		->where($map)
 		->select();
 		
 		foreach ($list as $key => $value) {
 			$str=$list[$key]['tID'];
 			$map['id']=array('in',$str);
 			$list[$key]['tids']=M("TbLable")->where($map)->select();
 		}	

 		foreach ($list as $key => $value){
 			$str3=$list[$key]['labfid'];
 			$str4=$list[$key]['labkid'];
 			$map3['ID']=array('in',$str3);
 			$map4['ID']=array('in',$str4);
 			$list[$key]['tids3']=M("TbTeclab")->where($map3)->select();
 			$list[$key]['tids4']=M("TbTeclab")->where($map4)->select();
 		}
 		
  		$this -> assign('_list',$list);
		
  		$this->meta_title = '参展项目';
   		$this->display();
	}
	
	//参展需求
	public function zxq($id=''){
		$demand = M(tb_demand);

		$map[zID] = $id;
		
		$list = $demand -> join('duijie_tb_exhdem on  duijie_tb_exhdem.xID = duijie_tb_demand.id')
		->join('duijie_tb_tecdem on duijie_tb_demand.rid=duijie_tb_tecdem.id')
		->where($map)
		->select();
       
		foreach ($list as $key => $value) {
			$str=$list[$key]['jsbq'];
			$mapp['id']=array('in',$str);
			$list[$key]['tids']=M("TbLable")->where($mapp)->select();
		}
			
		foreach ($list as $key => $value) {
			$str1=$list[$key]['fplace'];
			$str2=$list[$key]['place'];
			$map1['id']=array('in',$str1);
			$map2['id']=array('in',$str2);
			$list[$key]['tids1']=M("District")->where($map1)->select();
			$list[$key]['tids2']=M("District")->where($map2)->select();
		}
			
		foreach ($list as $key => $value){
			$str3=$list[$key]['ffield'];
			$str4=$list[$key]['field'];
			$map3['ID']=array('in',$str3);
			$map4['ID']=array('in',$str4);
			$list[$key]['tids3']=M("TbTeclab")->where($map3)->select();
			$list[$key]['tids4']=M("TbTeclab")->where($map4)->select();
		}
		
		dump($str1);
  		$this -> assign('_list',$list);
		
   		$this->meta_title = '参展项目';
   		$this->display();
	}
	
	//项目不通过
	public function xmcancel($id=''){
		$tecach = M(tb_tecach);
		$data['zstatus'] = '2';
		$tecach->where("id=$id")->save($data);
		$this->success('未通过',U('zxm'));
	}
	
	//需求不通过
	public function xqcancel($id=''){
		$demand = M(tb_demand);
		$data['zstatus'] = '2';
		$demand->where("id=$id")->save($data);
		
		$exh = M(tb_exhdem);
		$where[xID]=$id;
		$zid =$exh->where($where)->getField('zID');
		
		$this->success('未通过',U('zxq?id='.$zid));
	}
	
	//需求通过
	public function xqpass($id=''){
		$demand = M(tb_demand);
		$data['zstatus'] = '1';
		$demand->where("id=$id")->save($data);
		
		$exh = M(tb_exhdem);
		$where[xID]=$id;
		$zid =$exh->where($where)->getField('zID');
	    	
		$this->success('通过',U('zxq?id='.$zid));
	}
	
	//展会详情
	public function zdetail($id=''){

		$zhanhui = M(tb_exhinf);
 		$data = $zhanhui -> find($id);
 		$this -> assign('data',$data);
 		
 		$this->meta_title = '展会详情';
		$this->display();
	}
	
	//项目详情
public function xmdetail($id=''){
		
		$tecach = M(tb_tecach);
		
		$where['duijie_tb_tecach.id']= $id;
 		$data = $tecach ->join('duijie_tb_techol on duijie_tb_techol.id = duijie_tb_tecach.cID')
 		->join('duijie_tb_teccoo on duijie_tb_teccoo.cid=duijie_tb_tecach.hztype')
 		->join('duijie_tb_teccsd on duijie_tb_teccsd.sid=duijie_tb_tecach.csd')
 		->join('duijie_tb_patent on duijie_tb_patent.id = duijie_tb_tecach.patentid')
 		->join('duijie_tb_award on duijie_tb_award.ID = duijie_tb_tecach.awardid')
 		->join('duijie_tb_paper on duijie_tb_paper.id = duijie_tb_tecach.paperid')
 		->where($where) ->select();
 		
 		int_to_string($data,array('duijie'=>array(-1=>'未对接',0=>'对接中',1=>'对接已结束')));
 		
 		foreach ($data as $key => $value) {
 			$str=$data[$key]['fplace'];
 			$str2=$data[$key]['place'];
 			$map['id']=$str;
 			$map2['id']=$str2;
 			$data[$key]['tids']=M("District")->where($map)->select();
 			$data[$key]['tids2']=M("District")->where($map2)->select();
 		}
 		 
 		foreach ($data as $key => $value) {
 			$str3=$data[$key]['ffield'];
 			$str4=$data[$key]['field'];
 			$map3['ID']=$str3;
 			$map4['ID']=$str4;
 			$data[$key]['tids3']=M("TbTeclab")->where($map3)->select();
 			$data[$key]['tids4']=M("TbTeclab")->where($map4)->select();
 		}
 		
 		$this -> assign('data',$data);
 		 		
 		$this->meta_title = '项目详情';
		$this->display();
	}
	
	//需求详情
	public function xqdetail($id=''){
				$did=I('id');
	//			dump($did);
				$demand	=	M('tb_demand');
                
			   $where['duijie_tb_demand.id']=$did;
				$data=$demand->join('duijie_tb_tecdem on duijie_tb_tecdem.id=duijie_tb_demand.rid')
				->join('duijie_tb_teccoo on duijie_tb_teccoo.cid=duijie_tb_demand.cooperation')
				->join('duijie_tb_teccsd on duijie_tb_teccsd.sid=duijie_tb_demand.csd')
// 				->field('duijie_tb_teccoo.*,duijie_tb_demand.id idsss')
				->where($where)
				->select();
			//	dump($data);
				int_to_string($data,array('xdstatus'=>array(-1=>'未对接',0=>'对接中',1=>'对接已结束')));              //数字转为字符串
 			//	dump($data);
			    foreach ($data as $key => $value) {
			    	$str=$data[$key]['fplace'];
			    	$str2=$data[$key]['place'];
			    	$map['id']=$str;
			    	$map2['id']=$str2;
			    	$data[$key]['tids']=M("District")->where($map)->select();
			    	$data[$key]['tids2']=M("District")->where($map2)->select();
			    }
			    
			    foreach ($data as $key => $value) {
			    	$str3=$data[$key]['ffield'];
			    	$str4=$data[$key]['field'];
			    	$map3['ID']=$str3;
			    	$map4['ID']=$str4;
			    	$data[$key]['tids3']=M("TbTeclab")->where($map3)->select();
			    	$data[$key]['tids4']=M("TbTeclab")->where($map4)->select();
			    }
			  //  dump($data);
			   // $data->find($id);
			    $this->assign('data', $data);
// 			    dump($data);
			    
				$this->display();
	}
	
}